//
//  TutorChoiceViewController.m
//  Edumap
//
//  Created by 辰领科技 on 16/7/22.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "TutorChoiceViewController.h"
#import "TutorChoiceTableViewCell.h"
#import "TrainingOrderViewController.h"
#import "MentorToEditViewController.h"

static NSString *cellIdentifier = @"TutorChoiceTableViewCell";

@interface TutorChoiceViewController ()
<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@property (assign, nonatomic) NSInteger count;

@end

@implementation TutorChoiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    
    [_tableView registerNib:[UINib nibWithNibName:cellIdentifier bundle:nil] forCellReuseIdentifier:cellIdentifier];
    _tableView.dataSource = self;
    _tableView.delegate = self;
}


- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - 添加
- (IBAction)add:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"TeachStoryboard" bundle:nil];
    MentorToEditViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"MentorToEdit"];
    
    page.isEditContact = NO;
    
    [[Common getNavigation] pushViewController:page];
}

#pragma mark - <UITableViewDelegate&&UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

//定义 UITableView cell 的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

//定义 UITableView cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80*VerticalRatio();
}

//定义 UITableView cell 展示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TutorChoiceTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell= [[TutorChoiceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    for (UIView *view in cell.subviews) {
        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    
    cell.BGImage.image = [UIImage imageNamed:@"TutorChoice2"];
    [cell.button setImage:[UIImage imageNamed:@"SelectContact2"] forState:UIControlStateNormal];
    if (_count == indexPath.row) {
        cell.BGImage.image = [UIImage imageNamed:@"TutorChoice1"];
        [cell.button setImage:[UIImage imageNamed:@"SelectContact1"] forState:UIControlStateNormal];
    }
    
    
    cell.block = ^(){
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"TeachStoryboard" bundle:nil];
        MentorToEditViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"MentorToEdit"];
        
        page.isEditContact = YES;
        
        [[Common getNavigation] pushViewController:page];
    };
    
    return cell;
}

//定义 UITableView cell 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    _count = indexPath.row;
    [tableView reloadData];
    
    self.TutorChoiceBlock(YES);
    
    [self backBtn];
    
}

@end
